import { reqGetGoodsInfoData } from "@/api";

//这是一个请求搜索相关的数据操作文件
const state = {
  goodsInfo: {},
};
const actions = {
  // 1.根据参数，获取搜索数据
  async getSearchGoodsInfoData({ commit }, searchParams) {
    const result = await reqGetGoodsInfoData(searchParams);
    // 判断是否成功
    if (result.code === 200) {
      commit("SAVE_GOODS_INFO_DATA", result.data);
    } else {
      console.log(result.message);
    }
  },
};

const mutations = {
  SAVE_GOODS_INFO_DATA(state, goodsInfo) {
    state.goodsInfo = goodsInfo;
  },
};

const getters = {
  // 1. 商品列表
  goodsList(state) {
    return state.goodsInfo.goodsList;
  },
  // 2. 品牌列表
  trademarkList(state) {
    return state.goodsInfo.trademarkList;
  },
  // 3. 属性列表
  attrsList(state) {
    return state.goodsInfo.attrsList;
  },
  // 4.商品总数量
  total(state) {
    return state.goodsInfo.total;
  },
};

export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters,
};
